package com.softserveinc.autorent.rest;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import com.softserveinc.autorent.controller.CarVendorController;
import com.softserveinc.autorent.model.CarVendor;


@ManagedBean
@RequestScoped
public class CarVendorMB {
	
	@EJB
	private CarVendorController carVendorController;

	private CarVendor carVendor;
    private DataModel carVendorList;      
    
    public DataModel getCarVendorList() {
    	
    	 CarVendor cvnd= new CarVendor();
         cvnd.setId(1);
         cvnd.setName("Infinity");
         //List<CarVendor> lista = carVendorController.getAll();
         List<CarVendor> lista = new ArrayList<CarVendor>();
         lista.add(cvnd);
         cvnd= new CarVendor();
         cvnd.setId(2);
         cvnd.setName("Volskwagen");
         lista.add(cvnd);
         carVendorList = new ListDataModel(lista);
         return carVendorList;
         
//        List<CarVendor> lista = carVendorController.getAll();
//        carVendorList = new ListDataModel(lista);
//        return carVendorList;
    }

    public CarVendor getCarVendor() {
        return carVendor;
    }

    public void setCarVendor(CarVendor carVendor) {
        this.carVendor = carVendor;
    }

    public String prepareAddCarVendor(){
        carVendor = new CarVendor();
        return "Create person";
    }
          

    public String prepareUpdateCarVendor(){
        carVendor = (CarVendor)(carVendorList.getRowData());
        return "Create person";
    }

    public String deleteCarVendor(){

    	CarVendor carVendor = (CarVendor)(carVendorList.getRowData());    	
    	carVendorController.delete(carVendor);
        return "index";

    }

    public String addCarVendor(){    	
    	carVendorController.create(carVendor);
        return "index";
        
    }

    public String updateCarVendor(){    	
    	carVendorController.update(carVendor);
        return "index";

    }
}
